<!DOCTYPE html>
<html lang="en-us">
  <head>

    <meta http-equiv="content-type" content="text/html; charset=utf-8">
    
<meta charset="UTF-8">
<title>Bulk API | Elasticsearch Guide [7.7] | Elastic</title>
<link rel="home" href="index.html" title="Elasticsearch Guide [7.7]">
<link rel="up" href="docs.html" title="Document APIs">
<link rel="prev" href="docs-multi-get.html" title="Multi get (mget) API">
<link rel="next" href="docs-reindex.html" title="Reindex API">
<meta name="DC.type" content="Learn/Docs/Elasticsearch/Reference/7.7">
<meta name="DC.subject" content="Elasticsearch">
<meta name="DC.identifier" content="7.7">
<meta name="robots" content="noindex,nofollow">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <script src="https://cdn.optimizely.com/js/18132920325.js"></script>
    <link rel="apple-touch-icon" sizes="57x57" href="/apple-icon-57x57.png">
    <link rel="apple-touch-icon" sizes="60x60" href="/apple-icon-60x60.png">
    <link rel="apple-touch-icon" sizes="72x72" href="/apple-icon-72x72.png">
    <link rel="apple-touch-icon" sizes="76x76" href="/apple-icon-76x76.png">
    <link rel="apple-touch-icon" sizes="114x114" href="/apple-icon-114x114.png">
    <link rel="apple-touch-icon" sizes="120x120" href="/apple-icon-120x120.png">
    <link rel="apple-touch-icon" sizes="144x144" href="/apple-icon-144x144.png">
    <link rel="apple-touch-icon" sizes="152x152" href="/apple-icon-152x152.png">
    <link rel="apple-touch-icon" sizes="180x180" href="/apple-icon-180x180.png">
    <link rel="icon" type="image/png" href="/favicon-32x32.png" sizes="32x32">
    <link rel="icon" type="image/png" href="/android-chrome-192x192.png" sizes="192x192">
    <link rel="icon" type="image/png" href="/favicon-96x96.png" sizes="96x96">
    <link rel="icon" type="image/png" href="/favicon-16x16.png" sizes="16x16">
    <link rel="manifest" href="/manifest.json">
    <meta name="apple-mobile-web-app-title" content="Elastic">
    <meta name="application-name" content="Elastic">
    <meta name="msapplication-TileColor" content="#ffffff">
    <meta name="msapplication-TileImage" content="/mstile-144x144.png">
    <meta name="theme-color" content="#ffffff">
    <meta name="naver-site-verification" content="936882c1853b701b3cef3721758d80535413dbfd">
    <meta name="yandex-verification" content="d8a47e95d0972434">
    <meta name="localized" content="true">
    <meta name="st:robots" content="follow,index">
    <meta property="og:image" content="https://www.elastic.co/static/images/elastic-logo-200.png">
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon">
    <link rel="icon" href="/favicon.ico" type="image/x-icon">
    <link rel="apple-touch-icon-precomposed" sizes="64x64" href="/favicon_64x64_16bit.png">
    <link rel="apple-touch-icon-precomposed" sizes="32x32" href="/favicon_32x32.png">
    <link rel="apple-touch-icon-precomposed" sizes="16x16" href="/favicon_16x16.png">
    <!-- Give IE8 a fighting chance -->
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
    <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
    <link rel="stylesheet" type="text/css" href="/guide/static/styles.css">
  </head>

  <!--© 2015-2021 Elasticsearch B.V. Copying, publishing and/or distributing without written permission is strictly prohibited.-->

  <body>
    <!-- Google Tag Manager -->
    <script>dataLayer = [];</script><noscript><iframe src="//www.googletagmanager.com/ns.html?id=GTM-58RLH5" height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
    <script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start': new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0], j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src= '//www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f); })(window,document,'script','dataLayer','GTM-58RLH5');</script>
    <!-- End Google Tag Manager -->

    <!-- Global site tag (gtag.js) - Google Analytics -->
    <script async src="https://www.googletagmanager.com/gtag/js?id=UA-12395217-16"></script>
    <script>
      window.dataLayer = window.dataLayer || [];
      function gtag(){dataLayer.push(arguments);}
      gtag('js', new Date());
      gtag('config', 'UA-12395217-16');
    </script>

    <!--BEGIN QUALTRICS WEBSITE FEEDBACK SNIPPET-->
    <script type="text/javascript">
      (function(){var g=function(e,h,f,g){
      this.get=function(a){for(var a=a+"=",c=document.cookie.split(";"),b=0,e=c.length;b<e;b++){for(var d=c[b];" "==d.charAt(0);)d=d.substring(1,d.length);if(0==d.indexOf(a))return d.substring(a.length,d.length)}return null};
      this.set=function(a,c){var b="",b=new Date;b.setTime(b.getTime()+6048E5);b="; expires="+b.toGMTString();document.cookie=a+"="+c+b+"; path=/; "};
      this.check=function(){var a=this.get(f);if(a)a=a.split(":");else if(100!=e)"v"==h&&(e=Math.random()>=e/100?0:100),a=[h,e,0],this.set(f,a.join(":"));else return!0;var c=a[1];if(100==c)return!0;switch(a[0]){case "v":return!1;case "r":return c=a[2]%Math.floor(100/c),a[2]++,this.set(f,a.join(":")),!c}return!0};
      this.go=function(){if(this.check()){var a=document.createElement("script");a.type="text/javascript";a.src=g;document.body&&document.body.appendChild(a)}};
      this.start=function(){var a=this;window.addEventListener?window.addEventListener("load",function(){a.go()},!1):window.attachEvent&&window.attachEvent("onload",function(){a.go()})}};
      try{(new g(100,"r","QSI_S_ZN_emkP0oSe9Qrn7kF","https://znemkp0ose9qrn7kf-elastic.siteintercept.qualtrics.com/WRSiteInterceptEngine/?Q_ZID=ZN_emkP0oSe9Qrn7kF")).start()}catch(i){}})();
    </script><div id="ZN_emkP0oSe9Qrn7kF"><!--DO NOT REMOVE-CONTENTS PLACED HERE--></div>
    <!--END WEBSITE FEEDBACK SNIPPET-->

    <div id="elastic-nav" style="display:none;"></div>
    <script src="https://www.elastic.co/elastic-nav.js"></script>

    <!-- Subnav -->
    <div>
      <div>
        <div class="tertiary-nav d-none d-md-block">
          <div class="container">
            <div class="p-t-b-15 d-flex justify-content-between nav-container">
              <div class="breadcrum-wrapper"><span><a href="/guide/" style="font-size: 14px; font-weight: 600; color: #000;">Docs</a></span></div>
            </div>
          </div>
        </div>
      </div>
    </div>

    <div class="main-container">
      <section id="content">
        <div class="content-wrapper">

          <section id="guide" lang="en">
            <div class="container">
              <div class="row">
                <div class="col-xs-12 col-sm-8 col-md-8 guide-section">
                  <!-- start body -->
                  <div class="page_header">
<strong>IMPORTANT</strong>: No additional bug fixes or documentation updates
will be released for this version. For the latest information, see the
<a href="../current/index.html">current release documentation</a>.
</div>
<div id="content">
<div class="breadcrumbs">
<span class="breadcrumb-link"><a href="index.html">Elasticsearch Guide [7.7]</a></span>
»
<span class="breadcrumb-link"><a href="rest-apis.html">REST APIs</a></span>
»
<span class="breadcrumb-link"><a href="docs.html">Document APIs</a></span>
»
<span class="breadcrumb-node">Bulk API</span>
</div>
<div class="navheader">
<span class="prev">
<a href="docs-multi-get.html">« Multi get (mget) API</a>
</span>
<span class="next">
<a href="docs-reindex.html">Reindex API »</a>
</span>
</div>
<div class="section">
<div class="titlepage"><div><div>
<h2 class="title">
<a id="docs-bulk"></a>Bulk API<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/docs/bulk.asciidoc">edit</a>
</h2>
</div></div></div>

<p>Performs multiple indexing or delete operations in a single API call.
This reduces overhead and can greatly increase indexing speed.</p>
<div class="pre_wrapper lang-console">
<pre class="programlisting prettyprint lang-console">POST _bulk
{ "index" : { "_index" : "test", "_id" : "1" } }
{ "field1" : "value1" }
{ "delete" : { "_index" : "test", "_id" : "2" } }
{ "create" : { "_index" : "test", "_id" : "3" } }
{ "field1" : "value3" }
{ "update" : {"_id" : "1", "_index" : "test"} }
{ "doc" : {"field2" : "value2"} }</pre>
</div>
<div class="console_widget" data-snippet="snippets/1530.console"></div>
<div class="section">
<div class="titlepage"><div><div>
<h3 class="title">
<a id="docs-bulk-api-request"></a>Request<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/docs/bulk.asciidoc">edit</a>
</h3>
</div></div></div>
<p><code class="literal">POST /_bulk</code></p>
<p><code class="literal">POST /&lt;index&gt;/_bulk</code></p>
</div>

<div class="section">
<div class="titlepage"><div><div>
<h3 class="title">
<a id="docs-bulk-api-desc"></a>Description<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/docs/bulk.asciidoc">edit</a>
</h3>
</div></div></div>
<p>Provides a way to perform multiple <code class="literal">index</code>, <code class="literal">create</code>, <code class="literal">delete</code>, and <code class="literal">update</code> actions in a single request.</p>
<p>The actions are specified in the request body using a newline delimited JSON (NDJSON) structure:</p>
<div class="pre_wrapper lang-js">
<pre class="programlisting prettyprint lang-js">action_and_meta_data\n
optional_source\n
action_and_meta_data\n
optional_source\n
....
action_and_meta_data\n
optional_source\n</pre>
</div>
<p>The <code class="literal">index</code> and <code class="literal">create</code> actions expect a source on the next line,
and have the same semantics as the <code class="literal">op_type</code> parameter in the standard index API:
create fails if a document with the same name already exists in the index,
index adds or replaces a document as necessary.</p>
<p><code class="literal">update</code> expects that the partial doc, upsert,
and script and its options are specified on the next line.</p>
<p><code class="literal">delete</code> does not expect a source on the next line and
has the same semantics as the standard delete API.</p>
<div class="note admon">
<div class="icon"></div>
<div class="admon_content">
<p>The final line of data must end with a newline character <code class="literal">\n</code>.
Each newline character may be preceded by a carriage return <code class="literal">\r</code>.
When sending requests to the <code class="literal">_bulk</code> endpoint,
the <code class="literal">Content-Type</code> header should be set to <code class="literal">application/x-ndjson</code>.</p>
</div>
</div>
<p>Because this format uses literal <code class="literal">\n</code>'s as delimiters,
make sure that the JSON actions and sources are not pretty printed.</p>
<p>If you specify an index in the request URI,
it is used for any actions that don’t explicitly specify an index.</p>
<p>A note on the format: The idea here is to make processing of this as
fast as possible. As some of the actions are redirected to other
shards on other nodes, only <code class="literal">action_meta_data</code> is parsed on the
receiving node side.</p>
<p>Client libraries using this protocol should try and strive to do
something similar on the client side, and reduce buffering as much as
possible.</p>
<p>There is no "correct" number of actions to perform in a single bulk request.
Experiment with different settings to find the optimal size for your particular workload.</p>
<p>When using the HTTP API, make sure that the client does not send HTTP chunks,
as this will slow things down.</p>
<h5>
<a id="bulk-clients"></a>Client support for bulk requests<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/docs/bulk.asciidoc">edit</a>
</h5>
<p>Some of the officially supported clients provide helpers to assist with
bulk requests and reindexing of documents from one index to another:</p>
<div class="variablelist">
<dl class="variablelist">
<dt>
<span class="term">
Go
</span>
</dt>
<dd>
See <a href="https://github.com/elastic/go-elasticsearch/tree/master/_examples/bulk#indexergo" class="ulink" target="_top">esutil.BulkIndexer</a>
</dd>
<dt>
<span class="term">
Perl
</span>
</dt>
<dd>
See <a href="https://metacpan.org/pod/Search::Elasticsearch::Client::5_0::Bulk" class="ulink" target="_top">Search::Elasticsearch::Client::5_0::Bulk</a>
and <a href="https://metacpan.org/pod/Search::Elasticsearch::Client::5_0::Scroll" class="ulink" target="_top">Search::Elasticsearch::Client::5_0::Scroll</a>
</dd>
<dt>
<span class="term">
Python
</span>
</dt>
<dd>
See <a href="http://elasticsearch-py.readthedocs.org/en/master/helpers.html" class="ulink" target="_top">elasticsearch.helpers.*</a>
</dd>
<dt>
<span class="term">
JavaScript
</span>
</dt>
<dd>
See <a href="/guide/en/elasticsearch/client/javascript-api/current/client-helpers.html" class="ulink" target="_top">client.helpers.*</a>
</dd>
<dt>
<span class="term">
.NET
</span>
</dt>
<dd>
See <a href="/guide/en/elasticsearch/client/net-api/current/indexing-documents.html#bulkall-observable" class="ulink" target="_top"><code class="literal">BulkAllObservable</code></a>
</dd>
</dl>
</div>
<h5>
<a id="bulk-curl"></a>Submitting bulk requests with cURL<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/docs/bulk.asciidoc">edit</a>
</h5>
<p>If you’re providing text file input to <code class="literal">curl</code>, you <span class="strong strong"><strong>must</strong></span> use the
<code class="literal">--data-binary</code> flag instead of plain <code class="literal">-d</code>. The latter doesn’t preserve
newlines. Example:</p>
<div class="pre_wrapper lang-js">
<pre class="programlisting prettyprint lang-js">$ cat requests
{ "index" : { "_index" : "test", "_id" : "1" } }
{ "field1" : "value1" }
$ curl -s -H "Content-Type: application/x-ndjson" -XPOST localhost:9200/_bulk --data-binary "@requests"; echo
{"took":7, "errors": false, "items":[{"index":{"_index":"test","_type":"_doc","_id":"1","_version":1,"result":"created","forced_refresh":false}}]}</pre>
</div>
<h5>
<a id="bulk-optimistic-concurrency-control"></a>Optimistic Concurrency Control<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/docs/bulk.asciidoc">edit</a>
</h5>
<p>Each <code class="literal">index</code> and <code class="literal">delete</code> action within a bulk API call may include the
<code class="literal">if_seq_no</code> and <code class="literal">if_primary_term</code> parameters in their respective action
and meta data lines. The <code class="literal">if_seq_no</code> and <code class="literal">if_primary_term</code> parameters control
how operations are executed, based on the last modification to existing
documents. See <a class="xref" href="optimistic-concurrency-control.html" title="Optimistic concurrency control">Optimistic concurrency control</a> for more details.</p>
<h5>
<a id="bulk-versioning"></a>Versioning<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/docs/bulk.asciidoc">edit</a>
</h5>
<p>Each bulk item can include the version value using the
<code class="literal">version</code> field. It automatically follows the behavior of the
index / delete operation based on the <code class="literal">_version</code> mapping. It also
support the <code class="literal">version_type</code> (see <a class="xref" href="docs-index_.html#index-versioning" title="Versioning">versioning</a>).</p>
<h5>
<a id="bulk-routing"></a>Routing<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/docs/bulk.asciidoc">edit</a>
</h5>
<p>Each bulk item can include the routing value using the
<code class="literal">routing</code> field. It automatically follows the behavior of the
index / delete operation based on the <code class="literal">_routing</code> mapping.</p>
<h5>
<a id="bulk-wait-for-active-shards"></a>Wait For Active Shards<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/docs/bulk.asciidoc">edit</a>
</h5>
<p>When making bulk calls, you can set the <code class="literal">wait_for_active_shards</code>
parameter to require a minimum number of shard copies to be active
before starting to process the bulk request. See
<a class="xref" href="docs-index_.html#index-wait-for-active-shards" title="Active shards">here</a> for further details and a usage
example.</p>
<h5>
<a id="bulk-refresh"></a>Refresh<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/docs/bulk.asciidoc">edit</a>
</h5>
<p>Control when the changes made by this request are visible to search. See
<a class="xref" href="docs-refresh.html" title="?refresh">refresh</a>.</p>
<div class="note admon">
<div class="icon"></div>
<div class="admon_content">
<p>Only the shards that receive the bulk request will be affected by
<code class="literal">refresh</code>. Imagine a <code class="literal">_bulk?refresh=wait_for</code> request with three
documents in it that happen to be routed to different shards in an index
with five shards. The request will only wait for those three shards to
refresh. The other two shards that make up the index do not
participate in the <code class="literal">_bulk</code> request at all.</p>
</div>
</div>
<h5>
<a id="bulk-security"></a>Security<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/docs/bulk.asciidoc">edit</a>
</h5>
<p>See <a class="xref" href="url-access-control.html" title="URL-based access control">URL-based access control</a>.</p>
</div>

<div class="section">
<div class="titlepage"><div><div>
<h3 class="title">
<a id="docs-bulk-api-path-params"></a>Path parameters<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/docs/bulk.asciidoc">edit</a>
</h3>
</div></div></div>
<div class="variablelist">
<dl class="variablelist">
<dt>
<span class="term">
<code class="literal">&lt;index&gt;</code>
</span>
</dt>
<dd>
(Optional, string) Name of the index to perform the bulk actions against.
</dd>
</dl>
</div>
</div>

<div class="section">
<div class="titlepage"><div><div>
<h3 class="title">
<a id="docs-bulk-api-query-params"></a>Query parameters<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/docs/bulk.asciidoc">edit</a>
</h3>
</div></div></div>
<div class="variablelist">
<dl class="variablelist">
<dt>
<span class="term">
<code class="literal">pipeline</code>
</span>
</dt>
<dd>
(Optional, string) ID of the pipeline to use to preprocess incoming documents.
</dd>
<dt>
<span class="term">
<code class="literal">refresh</code>
</span>
</dt>
<dd>
(Optional, enum) If <code class="literal">true</code>, Elasticsearch refreshes the affected shards to make this
operation visible to search, if <code class="literal">wait_for</code> then wait for a refresh to make
this operation visible to search, if <code class="literal">false</code> do nothing with refreshes.
Valid values: <code class="literal">true</code>, <code class="literal">false</code>, <code class="literal">wait_for</code>. Default: <code class="literal">false</code>.
</dd>
<dt>
<span class="term">
<code class="literal">routing</code>
</span>
</dt>
<dd>
(Optional, string) Target the specified primary shard.
</dd>
<dt>
<span class="term">
<code class="literal">_source</code>
</span>
</dt>
<dd>
(Optional, string) True or false to return the <code class="literal">_source</code> field or not, or a
list of fields to return.
</dd>
<dt>
<span class="term">
<code class="literal">_source_excludes</code>
</span>
</dt>
<dd>
<p>
(Optional, string)
A comma-separated list of <a class="xref" href="mapping-source-field.html" title="_source field">source fields</a> to exclude from
the response.
</p>
<p>You can also use this parameter to exclude fields from the subset specified in
<code class="literal">_source_includes</code> query parameter.</p>
<p>If the <code class="literal">_source</code> parameter is <code class="literal">false</code>, this parameter is ignored.</p>
</dd>
<dt>
<span class="term">
<code class="literal">_source_includes</code>
</span>
</dt>
<dd>
<p>
(Optional, string)
A comma-separated list of <a class="xref" href="mapping-source-field.html" title="_source field">source fields</a> to
include in the response.
</p>
<p>If this parameter is specified, only these source fields are returned. You can
exclude fields from this subset using the <code class="literal">_source_excludes</code> query parameter.</p>
<p>If the <code class="literal">_source</code> parameter is <code class="literal">false</code>, this parameter is ignored.</p>
</dd>
<dt>
<span class="term">
<code class="literal">master_timeout</code>
</span>
</dt>
<dd>
(Optional, <a class="xref" href="common-options.html#time-units" title="Time units">time units</a>) Specifies the period of time to wait for
a connection to the master node. If no response is received before the timeout
expires, the request fails and returns an error. Defaults to <code class="literal">30s</code>.
</dd>
<dt>
<span class="term">
<code class="literal">timeout</code>
</span>
</dt>
<dd>
(Optional, <a class="xref" href="common-options.html#time-units" title="Time units">time units</a>) Specifies the period of time to wait for
a response. If no response is received before the timeout expires, the request
fails and returns an error. Defaults to <code class="literal">30s</code>.
</dd>
<dt>
<span class="term">
<code class="literal">wait_for_active_shards</code>
</span>
</dt>
<dd>
<p>(Optional, string) The number of shard copies that must be active before
proceeding with the operation. Set to <code class="literal">all</code> or any positive integer up
to the total number of shards in the index (<code class="literal">number_of_replicas+1</code>).
Default: 1, the primary shard.</p>
<p>See <a class="xref" href="docs-index_.html#index-wait-for-active-shards" title="Active shards">Active shards</a>.</p>
</dd>
</dl>
</div>
</div>

<div class="section">
<div class="titlepage"><div><div>
<h3 class="title">
<a id="bulk-api-request-body"></a>Request body<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/docs/bulk.asciidoc">edit</a>
</h3>
</div></div></div>
<p>The request body contains a newline-delimited list of <code class="literal">create</code>, <code class="literal">delete</code>, <code class="literal">index</code>,
and <code class="literal">update</code> actions and their associated source data.</p>
<div class="variablelist">
<dl class="variablelist">
<dt>
<span class="term">
<code class="literal">create</code>
</span>
</dt>
<dd>
<p>
(Optional, string)
Indexes the specified document if it does not already exist.
The following line must contain the source data to be indexed.
</p>
<div class="variablelist">
<dl class="variablelist">
<dt>
<span class="term">
<code class="literal">_index</code>
</span>
</dt>
<dd>
(Optional, string)
The name of the target index.
Required if not specified as a path parameter.
</dd>
<dt>
<span class="term">
<code class="literal">_id</code>
</span>
</dt>
<dd>
(Optional, string)
The document ID.
If no ID is specified, a document ID is automatically generated.
</dd>
</dl>
</div>
</dd>
<dt>
<span class="term">
<code class="literal">delete</code>
</span>
</dt>
<dd>
<p>
(Optional, string)
Removes the specified document from the index.
</p>
<div class="variablelist">
<dl class="variablelist">
<dt>
<span class="term">
<code class="literal">_index</code>
</span>
</dt>
<dd>
(Optional, string)
The name of the target index.
Required if not specified as a path parameter.
</dd>
<dt>
<span class="term">
<code class="literal">_id</code>
</span>
</dt>
<dd>
(Required, string) The document ID.
</dd>
</dl>
</div>
</dd>
<dt>
<span class="term">
<code class="literal">index</code>
</span>
</dt>
<dd>
<p>
(Optional, string)
Indexes the specified document.
If the document exists, replaces the document and increments the version.
The following line must contain the source data to be indexed.
</p>
<div class="variablelist">
<dl class="variablelist">
<dt>
<span class="term">
<code class="literal">_index</code>
</span>
</dt>
<dd>
(Optional, string)
The name of the target index.
Required if not specified as a path parameter.
</dd>
<dt>
<span class="term">
<code class="literal">_id</code>
</span>
</dt>
<dd>
(Optional, string)
The document ID.
If no ID is specified, a document ID is automatically generated.
</dd>
</dl>
</div>
</dd>
<dt>
<span class="term">
<code class="literal">update</code>
</span>
</dt>
<dd>
<p>
(Optional, string)
Performs a partial document update.
The following line must contain the partial document and update options.
</p>
<div class="variablelist">
<dl class="variablelist">
<dt>
<span class="term">
<code class="literal">_index</code>
</span>
</dt>
<dd>
(Optional, string)
The name of the target index.
Required if not specified as a path parameter.
</dd>
<dt>
<span class="term">
<code class="literal">_id</code>
</span>
</dt>
<dd>
(Required, string) The document ID.
</dd>
</dl>
</div>
</dd>
<dt>
<span class="term">
<code class="literal">doc</code>
</span>
</dt>
<dd>
(Optional, object)
The partial document to index.
Required for <code class="literal">update</code> operations.
</dd>
<dt>
<span class="term">
<code class="literal">&lt;fields&gt;</code>
</span>
</dt>
<dd>
(Optional, object)
The document source to index.
Required for <code class="literal">create</code> and <code class="literal">index</code> operations.
</dd>
</dl>
</div>
</div>

<div class="section child_attributes">
<div class="titlepage"><div><div>
<h3 class="title">
<a id="bulk-api-response-body"></a>Response body<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/docs/bulk.asciidoc">edit</a>
</h3>
</div></div></div>
<p>The bulk API’s response contains the individual results of each operation in the
request, returned in the order submitted. The success or failure of an
individual operation does not affect other operations in the request.</p>
<div class="sidebar">
<a id="bulk-partial-responses"></a>
<div class="titlepage"><div><div>
<p class="title"><strong>Partial responses</strong></p>
</div></div></div>
<p>To ensure fast responses, the bulk API will respond with partial results if one
or more shards fail. See <a class="xref" href="docs-replication.html#shard-failures" title="Shard failures">Shard failures</a> for more
information.</p>
</div>
<div class="variablelist">
<dl class="variablelist">
<dt>
<span class="term">
<code class="literal">took</code>
</span>
</dt>
<dd>
(integer)
How long, in milliseconds, it took to process the bulk request.
</dd>
<dt>
<span class="term">
<code class="literal">errors</code>
</span>
</dt>
<dd>
(boolean)
If <code class="literal">true</code>, one or more of the operations in the bulk request did not complete
successfully.
</dd>
<dt>
<span class="term">
<code class="literal">items</code>
</span>
</dt>
<dd>
<p>
(array of objects)
Contains the result of each operation in the bulk request, in the order they
were submitted.
</p>
<details open>
<summary class="title">Properties of <code class="literal">items</code> objects</summary>
<div class="content">
<div class="variablelist">
<dl class="variablelist">
<dt>
<span class="term">
&lt;action&gt;
</span>
</dt>
<dd>
<p>
(object)
The parameter name is an action associated with the operation. Possible values
are <code class="literal">create</code>, <code class="literal">delete</code>, <code class="literal">index</code>, and <code class="literal">update</code>.
</p>
<p>The parameter value is an object that contains information for the associated
operation.</p>
<details open>
<summary class="title">Properties of <code class="literal">&lt;action&gt;</code></summary>
<div class="content">
<div class="variablelist">
<dl class="variablelist">
<dt>
<span class="term">
<code class="literal">_index</code>
</span>
</dt>
<dd>
(string)
The index name or alias associated with the operation.
</dd>
<dt>
<span class="term">
<code class="literal">_type</code>
</span>
</dt>
<dd>
(string)
The document type associated with the operation. Elasticsearch indices now support a
single document type: <code class="literal">_doc</code>. See <a class="xref" href="removal-of-types.html" title="Removal of mapping types"><em>Removal of mapping types</em></a>.
</dd>
<dt>
<span class="term">
<code class="literal">_id</code>
</span>
</dt>
<dd>
(integer)
The document ID associated with the operation.
</dd>
<dt>
<span class="term">
<code class="literal">_version</code>
</span>
</dt>
<dd>
<p>
(integer)
The document version associated with the operation. The document version is
incremented each time the document is updated.
</p>
<p>This parameter is only returned for successful actions.</p>
</dd>
<dt>
<span class="term">
<code class="literal">result</code>
</span>
</dt>
<dd>
<p>
(string)
Result of the operation. Successful values are <code class="literal">created</code>, <code class="literal">deleted</code>, and
<code class="literal">updated</code>.
</p>
<p>This parameter is only returned for successful operations.</p>
</dd>
<dt>
<span class="term">
<code class="literal">_shards</code>
</span>
</dt>
<dd>
<p>
(object)
Contains shard information for the operation.
</p>
<p>This parameter is only returned for successful operations.</p>
<details open>
<summary class="title">Properties of <code class="literal">_shards</code></summary>
<div class="content">
<div class="variablelist">
<dl class="variablelist">
<dt>
<span class="term">
<code class="literal">total</code>
</span>
</dt>
<dd>
(integer)
Number of shards the operation attempted to execute on.
</dd>
<dt>
<span class="term">
<code class="literal">successful</code>
</span>
</dt>
<dd>
(integer)
Number of shards the operation succeeded on.
</dd>
<dt>
<span class="term">
<code class="literal">failed</code>
</span>
</dt>
<dd>
(integer)
Number of shards the operation attempted to execute on but failed.
</dd>
</dl>
</div>
</div>
</details>
</dd>
<dt>
<span class="term">
<code class="literal">_seq_no</code>
</span>
</dt>
<dd>
<p>
(integer)
The sequence number assigned to the document for the operation.
Sequence numbers are used to ensure an older version of a document
doesn’t overwrite a newer version. See <a class="xref" href="docs-index_.html#optimistic-concurrency-control-index" title="Optimistic concurrency control">Optimistic concurrency control</a>.
</p>
<p>This parameter is only returned for successful operations.</p>
</dd>
<dt>
<span class="term">
<code class="literal">_primary_term</code>
</span>
</dt>
<dd>
<p>
(integer)
The primary term assigned to the document for the operation.
See <a class="xref" href="docs-index_.html#optimistic-concurrency-control-index" title="Optimistic concurrency control">Optimistic concurrency control</a>.
</p>
<p>This parameter is only returned for successful operations.</p>
</dd>
<dt>
<span class="term">
<code class="literal">status</code>
</span>
</dt>
<dd>
(integer)
HTTP status code returned for the operation.
</dd>
<dt>
<span class="term">
<code class="literal">error</code>
</span>
</dt>
<dd>
<p>
(object)
Contains additional information about the failed operation.
</p>
<p>The parameter is only returned for failed operations.</p>
<details open>
<summary class="title">Properties of <code class="literal">error</code></summary>
<div class="content">
<div class="variablelist">
<dl class="variablelist">
<dt>
<span class="term">
<code class="literal">type</code>
</span>
</dt>
<dd>
(string)
Error type for the operation.
</dd>
<dt>
<span class="term">
<code class="literal">reason</code>
</span>
</dt>
<dd>
(string)
Reason for the failed operation.
</dd>
<dt>
<span class="term">
<code class="literal">index_uuid</code>
</span>
</dt>
<dd>
(string)
The universally unique identifier (UUID) of the index associated with the failed
operation.
</dd>
<dt>
<span class="term">
<code class="literal">shard</code>
</span>
</dt>
<dd>
(string)
ID of the shard associated with the failed operation.
</dd>
<dt>
<span class="term">
<code class="literal">index</code>
</span>
</dt>
<dd>
(string)
The index name or alias associated with the failed operation.
</dd>
</dl>
</div>
</div>
</details>
</dd>
</dl>
</div>
</div>
</details>
</dd>
</dl>
</div>
</div>
</details>
</dd>
</dl>
</div>
</div>

<div class="section">
<div class="titlepage"><div><div>
<h3 class="title">
<a id="docs-bulk-api-example"></a>Examples<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/docs/bulk.asciidoc">edit</a>
</h3>
</div></div></div>
<div class="pre_wrapper lang-console">
<pre class="programlisting prettyprint lang-console">POST _bulk
{ "index" : { "_index" : "test", "_id" : "1" } }
{ "field1" : "value1" }
{ "delete" : { "_index" : "test", "_id" : "2" } }
{ "create" : { "_index" : "test", "_id" : "3" } }
{ "field1" : "value3" }
{ "update" : {"_id" : "1", "_index" : "test"} }
{ "doc" : {"field2" : "value2"} }</pre>
</div>
<div class="console_widget" data-snippet="snippets/1531.console"></div>
<p>The API returns the following result:</p>
<div class="pre_wrapper lang-console-result">
<pre class="programlisting prettyprint lang-console-result">{
   "took": 30,
   "errors": false,
   "items": [
      {
         "index": {
            "_index": "test",
            "_type": "_doc",
            "_id": "1",
            "_version": 1,
            "result": "created",
            "_shards": {
               "total": 2,
               "successful": 1,
               "failed": 0
            },
            "status": 201,
            "_seq_no" : 0,
            "_primary_term": 1
         }
      },
      {
         "delete": {
            "_index": "test",
            "_type": "_doc",
            "_id": "2",
            "_version": 1,
            "result": "not_found",
            "_shards": {
               "total": 2,
               "successful": 1,
               "failed": 0
            },
            "status": 404,
            "_seq_no" : 1,
            "_primary_term" : 2
         }
      },
      {
         "create": {
            "_index": "test",
            "_type": "_doc",
            "_id": "3",
            "_version": 1,
            "result": "created",
            "_shards": {
               "total": 2,
               "successful": 1,
               "failed": 0
            },
            "status": 201,
            "_seq_no" : 2,
            "_primary_term" : 3
         }
      },
      {
         "update": {
            "_index": "test",
            "_type": "_doc",
            "_id": "1",
            "_version": 2,
            "result": "updated",
            "_shards": {
                "total": 2,
                "successful": 1,
                "failed": 0
            },
            "status": 200,
            "_seq_no" : 3,
            "_primary_term" : 4
         }
      }
   ]
}</pre>
</div>
<h5>
<a id="bulk-update"></a>Bulk update example<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/docs/bulk.asciidoc">edit</a>
</h5>
<p>When using the <code class="literal">update</code> action, <code class="literal">retry_on_conflict</code> can be used as a field in
the action itself (not in the extra payload line), to specify how many
times an update should be retried in the case of a version conflict.</p>
<p>The <code class="literal">update</code> action payload supports the following options: <code class="literal">doc</code>
(partial document), <code class="literal">upsert</code>, <code class="literal">doc_as_upsert</code>, <code class="literal">script</code>, <code class="literal">params</code> (for
script), <code class="literal">lang</code> (for script), and <code class="literal">_source</code>. See update documentation for details on
the options. Example with update actions:</p>
<div class="pre_wrapper lang-console">
<pre class="programlisting prettyprint lang-console">POST _bulk
{ "update" : {"_id" : "1", "_index" : "index1", "retry_on_conflict" : 3} }
{ "doc" : {"field" : "value"} }
{ "update" : { "_id" : "0", "_index" : "index1", "retry_on_conflict" : 3} }
{ "script" : { "source": "ctx._source.counter += params.param1", "lang" : "painless", "params" : {"param1" : 1}}, "upsert" : {"counter" : 1}}
{ "update" : {"_id" : "2", "_index" : "index1", "retry_on_conflict" : 3} }
{ "doc" : {"field" : "value"}, "doc_as_upsert" : true }
{ "update" : {"_id" : "3", "_index" : "index1", "_source" : true} }
{ "doc" : {"field" : "value"} }
{ "update" : {"_id" : "4", "_index" : "index1"} }
{ "doc" : {"field" : "value"}, "_source": true}</pre>
</div>
<div class="console_widget" data-snippet="snippets/1532.console"></div>
<h5>
<a id="bulk-failures-ex"></a>Example with failed actions<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/docs/bulk.asciidoc">edit</a>
</h5>
<p>The following bulk API request includes operations that update non-existent
documents.</p>
<div class="pre_wrapper lang-console">
<pre class="programlisting prettyprint lang-console">POST /_bulk
{ "update": {"_id": "5", "_index": "index1"} }
{ "doc": {"my_field": "foo"} }
{ "update": {"_id": "6", "_index": "index1"} }
{ "doc": {"my_field": "foo"} }
{ "create": {"_id": "7", "_index": "index1"} }
{ "my_field": "foo" }</pre>
</div>
<div class="console_widget" data-snippet="snippets/1533.console"></div>
<p>Because these operations cannot complete successfully, the API returns a
response with an <code class="literal">errors</code> flag of <code class="literal">true</code>.</p>
<p>The response also includes an <code class="literal">error</code> object for any failed operations. The
<code class="literal">error</code> object contains additional information about the failure, such as the
error type and reason.</p>
<div class="pre_wrapper lang-console-result">
<pre class="programlisting prettyprint lang-console-result">{
  "took": 486,
  "errors": true,
  "items": [
    {
      "update": {
        "_index": "index1",
        "_type" : "_doc",
        "_id": "5",
        "status": 404,
        "error": {
          "type": "document_missing_exception",
          "reason": "[_doc][5]: document missing",
          "index_uuid": "aAsFqTI0Tc2W0LCWgPNrOA",
          "shard": "0",
          "index": "index1"
        }
      }
    },
    {
      "update": {
        "_index": "index1",
        "_type" : "_doc",
        "_id": "6",
        "status": 404,
        "error": {
          "type": "document_missing_exception",
          "reason": "[_doc][6]: document missing",
          "index_uuid": "aAsFqTI0Tc2W0LCWgPNrOA",
          "shard": "0",
          "index": "index1"
        }
      }
    },
    {
      "create": {
        "_index": "index1",
        "_type" : "_doc",
        "_id": "7",
        "_version": 1,
        "result": "created",
        "_shards": {
          "total": 2,
          "successful": 1,
          "failed": 0
        },
        "_seq_no": 0,
        "_primary_term": 1,
        "status": 201
      }
    }
  ]
}</pre>
</div>
<p>To return only information about failed operations, use the
<a class="xref" href="common-options.html#common-options-response-filtering" title="Response Filtering"><code class="literal">filter_path</code></a> query parameter with an
argument of <code class="literal">items.*.error</code>.</p>
<div class="pre_wrapper lang-console">
<pre class="programlisting prettyprint lang-console">POST /_bulk?filter_path=items.*.error
{ "update": {"_id": "5", "_index": "index1"} }
{ "doc": {"my_field": "baz"} }
{ "update": {"_id": "6", "_index": "index1"} }
{ "doc": {"my_field": "baz"} }
{ "update": {"_id": "7", "_index": "index1"} }
{ "doc": {"my_field": "baz"} }</pre>
</div>
<div class="console_widget" data-snippet="snippets/1534.console"></div>
<p>The API returns the following result.</p>
<div class="pre_wrapper lang-console-result">
<pre class="programlisting prettyprint lang-console-result">{
  "items": [
    {
      "update": {
        "error": {
          "type": "document_missing_exception",
          "reason": "[_doc][5]: document missing",
          "index_uuid": "aAsFqTI0Tc2W0LCWgPNrOA",
          "shard": "0",
          "index": "index1"
        }
      }
    },
    {
      "update": {
        "error": {
          "type": "document_missing_exception",
          "reason": "[_doc][6]: document missing",
          "index_uuid": "aAsFqTI0Tc2W0LCWgPNrOA",
          "shard": "0",
          "index": "index1"
        }
      }
    }
  ]
}</pre>
</div>
</div>

</div>
<div class="navfooter">
<span class="prev">
<a href="docs-multi-get.html">« Multi get (mget) API</a>
</span>
<span class="next">
<a href="docs-reindex.html">Reindex API »</a>
</span>
</div>
</div>

                  <!-- end body -->
                </div>
                <div class="col-xs-12 col-sm-4 col-md-4" id="right_col">
                  <div id="rtpcontainer" style="display: block;">
                    <div class="mktg-promo">
                      <h3>Most Popular</h3>
                      <ul class="icons">
                        <li class="icon-elasticsearch-white"><a href="https://www.elastic.co/webinars/getting-started-elasticsearch?baymax=default&amp;elektra=docs&amp;storm=top-video">Get Started with Elasticsearch: Video</a></li>
                        <li class="icon-kibana-white"><a href="https://www.elastic.co/webinars/getting-started-kibana?baymax=default&amp;elektra=docs&amp;storm=top-video">Intro to Kibana: Video</a></li>
                        <li class="icon-logstash-white"><a href="https://www.elastic.co/webinars/introduction-elk-stack?baymax=default&amp;elektra=docs&amp;storm=top-video">ELK for Logs &amp; Metrics: Video</a></li>
                      </ul>
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </section>

        </div>


<div id="elastic-footer"></div>
<script src="https://www.elastic.co/elastic-footer.js"></script>
<!-- Footer Section end-->

      </section>
    </div>

<script src="/guide/static/jquery.js"></script>
<script type="text/javascript" src="/guide/static/docs.js"></script>
<script type="text/javascript">
  window.initial_state = {}</script>
  </body>
</html>
